home *** CD-ROM | disk | FTP | other *** search
/ Die Ultimative Software-P…i Collection 1996 & 1997 / Die Ultimative Software-Pakete CD-ROM fur Atari Collection 1996 & 1997.iso / g / gnu_c / crssrc16.zoo / widget / wpage.c < prev   
Encoding:
C/C++ Source or Header  |  1991-05-03  |  3.2 KB  |  151 lines

  1. /*****************************************************************************
  2. /*  FILE:        wpage.c
  3. /*  DATE:        August 1988.
  4. /*  AUTHOR:        Richard A. Culshaw.
  5. /*  DESCRIPTION:    A small demonstration program using the widgets.
  6. /* DISCLAIMER:        This file is deemed to be public-domain, on the simple
  7. /*            provisos that this section remains in this file and
  8. /*            that code using it do not do so for monetary gain.
  9. /*            Neither the author, nor the authors employees at the
  10. /*            time of developing this code, accept any liability or
  11. /*            responsibility for the use, abuse or misuse of this
  12. /*            code.
  13. /*****************************************************************************/
  14.  
  15. #include <stdio.h>
  16. #include <string.h>
  17. #include <widget.h>
  18.  
  19. WIDGET    title, nlcmd, npcmd, qcmd, finput, gfile, frac;
  20. char    filename[14];
  21. char    string[20];
  22. int    nolines;
  23. int    filepresent;
  24. FILE    *f;
  25. long    size, ftell();
  26.  
  27. int readline ()
  28. {
  29.     int   i;
  30.     int      space;
  31.     char  buffer [80];
  32.     int   count;
  33.     int   ch;
  34.  
  35.     count = 0;
  36.       while ((count < 79) && (ch = getc(f)) && (ch != '\n') && (ch != EOF))
  37.         if (ch == '\t') {
  38.         space = 8 - count % 8;
  39.         for (i=0; i<space; i++)
  40.             buffer [count++] = ' ';
  41.          }
  42.         else
  43.             buffer [count++] = ch;
  44.         buffer [count] = '\0';
  45.         if ((count > 0) || (ch == '\n'));
  46.         report (buffer);
  47.     return (ch); 
  48. }
  49.  
  50. changefrac ()
  51. {
  52.     long  cur;
  53.     char  data[5];
  54.  
  55.     cur = ftell (f);
  56.     sprintf (data, "%ld%%", cur*100L/size);
  57.     changelblwidget (frac, data, RIGHTJUST|NOHIGH);
  58. }
  59.  
  60.  
  61. nextline ()
  62. {
  63.     int ch;
  64.  
  65.     highlight (nlcmd);
  66.     ch = readline ();
  67.     dehighlight (nlcmd);
  68.     if (ch == EOF) {
  69.     deactivate (npcmd, BLANK);
  70.     deactivate (nlcmd, BLANK);
  71.     }
  72.     changefrac ();
  73.     widgetinput ();
  74. }
  75.  
  76. nextpage ()
  77. {
  78.     int   line  = 0;
  79.     int      ch;
  80.  
  81.     highlight (npcmd);
  82.     cleartextwindow ();
  83.  
  84.     while ((line++ != nolines) && ((ch = readline()) != EOF)) 
  85.     ;
  86.     
  87.     dehighlight (npcmd);
  88.     if (ch == EOF) {
  89.     deactivate (npcmd, BLANK);
  90.     deactivate (nlcmd, BLANK);
  91.     }
  92.  
  93.     changefrac ();
  94.     widgetinput ();
  95. }
  96.  
  97. quit ()
  98. {
  99.     endwidgets ();
  100. }
  101.  
  102. getfile ()
  103. {
  104.     int i;
  105.  
  106.     if (!filepresent) {
  107.         highlight (gfile);
  108.         killwidget (title);
  109.         changelblwidget (frac, "", RIGHTJUST|NOHIGH);
  110.         finput = mkinpwidget ("file", (int)NULL, filename, 14, 0, 0, EXEC);
  111.         killwidget (finput);
  112.     }
  113.     else
  114.     filepresent = FALSE;
  115.     for (i=5; i<=20; i++)
  116.        string [i] = filename [i-5]; 
  117.     dehighlight (gfile);
  118.     f = fopen (filename, "r");
  119.     if (f == NULL) {
  120.     cleartextwindow ();    
  121.     report ("File does not exist. Try again");
  122.     getfile ();
  123.     }
  124.     title = mklblwidget (string, CENTRE, 0, 0);
  125.     fseek (f, 0L, 2);
  126.     size = ftell (f);
  127.     rewind (f);
  128.     activate (nlcmd);
  129.     activate (npcmd);
  130.     nextpage ();
  131. }
  132.  
  133. main (argc, argv)
  134. int    argc;
  135. char    *argv[];
  136. {
  137.     initialisewidgets ();
  138.     if (argc > 1) {
  139.     strcpy (filename, argv[1]);
  140.     filepresent = TRUE;
  141.     }
  142.     strcpy (string, "File=");
  143.     qcmd = mkcmdwidget ("Quit", 'q', quit, 0);
  144.     nlcmd = mkcmdwidget ("Next line", 'n', nextline, 0);
  145.     npcmd = mkcmdwidget ("Next page", 'N', nextpage, 0);
  146.     gfile = mkcmdwidget ("Get file", 'f', getfile, 0);
  147.     frac = mklblwidget ("", CENTRE, 4, 0);
  148.     nolines = opentextwindow (0, HORIZONTAL);
  149.     getfile ();
  150. }    
  151.